package com.jr.controller;

import com.jr.entry.User;
import com.jr.service.UserService;
import com.jr.util.ResultObjcet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController /*替换@RestController=@Controller + @ResponseBody*/
@RequestMapping("/User/")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private ResultObjcet result;


    @RequestMapping("add")
    public ResultObjcet add(User user){
        if (user.getUsername() != "" && user.getPassword() != ""){
            int b=userService.register(user);
            result.setResult(b);
        }else {
            result.setResult("");
        }
        return result;
    }


    @RequestMapping("login")
    public User login(User user){
        return  userService.login(user);
    }
}
